package com.atguigu.seckill.controller;

import com.atguigu.seckill.service.SecKillSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SecDealComtroller {

    @Autowired
    SecKillSevice secKillSevice;


    /**
     * 商品进行秒杀(秒杀开始)
     *
     * @param killId
     * @param key
     * @param num
     * @return
     */
    @GetMapping(value = "/kill")
//    770944573091455a8ef408e08060c9f22
    public String seckill(@RequestParam("killId") String killId,
                          @RequestParam("key") String key,
                          @RequestParam("num") Integer num,
                          Model model) throws InterruptedException {
        //进行秒杀流程
        String order_sn = secKillSevice.dealSecKill(killId, key, num);
        model.addAttribute("orderSn", order_sn);
        return "success";
    }

}
